package com.ztom.daily.n2022.m3;

/**
 * 7 进制数
 * <p>
 * https://leetcode-cn.com/problems/base-7/
 *
 * @author ZhangTao
 */
public class Day07ConvertToBase7 {

    public String convertToBase7(int num) {
        if (num == 0) {
            return "0";
        }

        StringBuilder builder = new StringBuilder();
        boolean isNegative = num < 0;
        num = Math.abs(num);
        while (num > 0) {
            builder.append(num % 7);
            num /= 7;
        }
        if (isNegative) {
            builder.append("-");
        }
        return builder.reverse().toString();
    }
}
